(function()
{
	var leftFun = function()
	{
		this._setFunction = [];
		this._pathi = 1;
		this._topHeadNav = false;
		this.maincontent = {}; // 主框属性
		this._setEvent();
	};
	// 兼容（过渡）处理
	leftFun.prototype.hideTop = function()
	{
	}
	// 设置点击方法
	leftFun.prototype._setEvent = function()
	{
		if (leftFun.prototype._)
			return;
		leftFun.prototype._ = true;
		var that = this;
		// hash 变化
		window.addEventListener('hashchange', function(e)
		{
			if (!app.isSinglePage() && (!app.hash.changeTime || new Date().getTime() - app.hash.changeTime > 100))
			{
				var hash = app.hash();
				if (hash)
				{
					that.goPage(hash, true);
				}
			}
		}, false);
		// 顶部选择商家
		$('.main-header #business').on('click', function()
		{
			app.selectBusiness(null, true);
		});
		// 顶部按钮
		$("#RightTopIconUL").on('click', 'li', function()
		{
			if (this.id == 'exit')
			{
				login.logOut(null, false, false, true);
			}
			if (this.id == 'refresh')
			{
				app.refresh();
			}
		});
		// 顶部导航栏
		$('.headNavBar').on('click', " li", function()
		{
			var path = $(this).attr('id').substring(4);
			var datalevel = parseInt($(this).attr('data-level'));
			that.runHeadNav(path, datalevel, true);
		});
		// 手机的关闭弹出框的关闭按钮
		$('body').on('click', ".layui-layer .layer_close", function()
		{
			var layerIndex = $(this).parents('.layui-layer').attr('times');
			if (layerIndex)
			{
				if ($(this).parents('.fulllayer').length > 0)
					closeFullLayerOne(layerIndex);
				else
					layer.close(layerIndex);
			}
		});
		// 弹出框右上菜单
		$('body').on('click', ".layui-layer .fulllayerrightmenu", function()
		{
			var rightmenuId = $(this).attr('id');
			if (rightmenuId && left.fulllayerrightmenu && left.fulllayerrightmenu[rightmenuId])
			{
				var off = getOffset(this);
				app.rightMenu(off.left + 40, app.vm ? -20 : off.top, 200, left.fulllayerrightmenu[rightmenuId]);
			}
		});
		// 左上角弹出/消失左侧菜单
		$('body').on('mouseup', ".navbar .sidebar-toggle.toleftright", function()
		{
			that.bodyLeftMenu(true, null);
		});
		if ($(window).width() > 600)
		{
			$('body').on('click', "#maincontent span.righttopclose", function()
			{
				that.goBack();
				var p = left.navBarList;
				if (p.length <= 0)
					$('#maincontent span.righttopclose').hide();
			});
		}
		// 左上角弹出左侧菜单
		$('body').on('click', '.minlogo', function()
		{
			if (that.isShowLeftMenu || app.haveNote)
				return;
			that.isShowLeftMenu = true;
			that.bodyLeftMenu(true, null, true);
			if ($('#showLeftMenu').length == 0)
			{
				var h = '<div id="showLeftMenu" style="position:fixed;top:0;left:300px;width:100%;height:100%;z-index:9999998;background-color:rgb(0,0,0);opacity:0.1;"></div>';
				$('body').append(h);
			}
			else
				$('#showLeftMenu').show();
		});
		// 关闭右侧菜单
		$('body').on('mousemove', '#showLeftMenu', function(e)
		{
			if (that.isShowLeftMenu)
			{
				that.isShowLeftMenu = false;
				that.bodyLeftMenu(true, null, false);
			}
			$('#showLeftMenu').hide();
		});
		// 右键菜单
		$('body').on('click', "ul.apprightmenu li", function()
		{
			var k = $(this).attr('key');
			if (!k)
				k = $(this).attr('data');
			if (!k)
				k = '';
			var re;
			if (app.rightMenuBackfun)
			{
				re = app.rightMenuBackfun(k, $(this).html(), this);
			}
			if (re !== false)
				app.rightMenu();
		});
		// 长按
		$('body').longPress(function(et, e, x, y, x0, y0, isend, inscroll, dt)
		{
			e = e || event;
			if (!et)
				return;
			var t1 = $(et).hasClass('fulllayer');
			var t2 = $(et).hasClass('sliding');
			if ($(et).hasClass('odd') && (et.tagName == 'TR' || et.tagName == 'UL'))
			{
				// 长按tr
				tableFun.prototype._clickRightMenu(et, e, x, y);
				return;
			}
			else if ($(et).hasClass('maininput') && et.tagName == 'DIV')
			{
				// 长按主输入框
				$(et).attr('contenteditable', 'plaintext-only');
				$(et).css('background-color', '#ddd');
			}
			else if ($(et).hasClass('jp-backspace'))
			{
				// 长按键盘清除键
				$('#JP_thisjiangpan .t80 span').html('');
				that.jp.initvalue = '';
				if (that.jp.enterfun)
					that.jp.enterfun('', false, true);
			}
			else if ($('#JP_thisjiangpan').length <= 0 && et.tagName == 'INPUT' && et.type != 'file')
			{
				// 无键盘时长按 INPUT（试图弹出键盘）
				if (!app.needWTPJp() || ($(et).hasClass('btnfun') && et.readOnly))
					return;
				that.loadJp(et);
			}
			else
			{
				var fun = $(et).attr('onlongpress');
				if (fun)
					eval(fun);
			}
		});
		// 单击输入框
		$('body').on('click', "input.editabled", function()
		{
			if (!app.needWTPJp() || ($(this).hasClass('btnfun') && this.readOnly))
				return;
			if (this.readOnly && $(this).attr('editabled') && $('#JP_thisjiangpan').length <= 0)
				that.loadJp(this);
		});
		// 键盘按下
		document.onkeydown = function(e)
		{
			that.showLogoFace(null, true);
			e = e || event;
			if (e.ctrlKey)
			{
				// 凭证管理
				if (window.assetsVoucher && assetsVoucher.saveValueDataLasti > 0)
				{
					if (e.keyCode == 83 || e.keyCode == 65 || e.keyCode == 73) // s a i
					{
						if (e.keyCode == 83)
							assetsVoucher.submitValue();
						else if (e.keyCode == 65)
							assetsVoucher.submitValue(true);
						else if (e.keyCode == 73)
							assetsVoucher.addHang(true);
						return false;
					}
				}
				return;
			}
			var isie = (document.all) ? true : false;
			if (isie)
			{
				var key = window.event.keyCode;
				var ev = window.event;
			}
			else
			{
				var key = e.which;
				var ev = e;
			}
			if (key == 9)
			{
				var t = $("textarea:focus");
				if (app.vm || t.length <= 0)
					return;
				t.insertContent("\t");
				if (isie)
				{
					ev.keyCode = 0;
					ev.returnValue = false;
				}
				else
				{
					ev.which = 0;
					ev.preventDefault();
				}
			}
			else
			{
				// 处理主输入框的键盘、扫描枪输入
				while (app.mainInputObjId && $('#' + app.mainInputObjId).length == 0)
				{
					app.setMainInputObj();
				}
				if (that.jp.layerIndex > 0)
				{
					that.jp('close');
				}
				if (!app.mainInputObjId)
					return;
				var f = $(':focus');
				if (f.length > 0 && f[0].tagName == 'INPUT' && !$(f[0]).hasClass('maininput'))
				{
					// 当前焦点并非主输入框
					return;
				}
				if (app.mainInputObjId && $('#' + app.mainInputObjId).length > 0)
				{
					var k = $('#' + app.mainInputObjId);
					if (k.length > 0 && !k.is(':focus') && $(':focus').length <= 0)
					{
						if (key == 13)
						{
							app.play('ding');
							layer.msg('not focus');
						}
						k[0].focus();
					}
					var maininput = k.length > 0 ? k[0] : (ev.target.tagName == 'INPUT' ? ev.target : null);
					if (maininput)
					{
						if (key == 13)
						{
							if (app.mainInputSubmitFun)
							{
								var v = $(k[0]).val();
								v = (v + ' ').trim();
								app.mainInputSubmitFun(v, true);
							}
						}
						else if (k[0].readOnly && $(k[0]).attr('editabled'))
						{
							k[0].readOnly = false;
						}
					}
				}
			}
		}
		// 输出框焦点失去事件
		$('body').on('blur', "input", function()
		{
			if (app.needWTPJp() && $(this).attr('editabled') && !this.readOnly)
				this.readOnly = true;
		});
		$('body').on('mousemove', function(e)
		{
			that.showLogoFace(null, true);
		});
		$('body').on('touchmove', function(e)
		{
			that.showLogoFace(null, true);
		});
		$('body').on('click', function(e)
		{
			that.showLogoFace(null, true);
		});
		// 禁止右键等内容菜单
		document.oncontextmenu = function(e)
		{
			e = e || event;
			var k = null;
			if (e.path && $(e.path[0]).length > 0)
			{
				k = $(e.path[0])[0];
				if (k && $(k).hasClass('allowrightmenu') || $(k).parents('.allowrightmenu').length > 0)
					return true;
			}
			return false;
		}
		$(window).resize(function()
		{
			app.setAppSize();
			that.showNavBar();
			that.setWrapperHeight();
		});
		// 鼠标滚轮事件
		var mousewheelTimer = 0;
		$('body').on('mousewheel', '.fullLayer', function()
		{
			if ($(this).find('.layui-layer-content').height() >= $(this).find('.layui-layer-content>div').height())
			{
				// 没有发生滚动
				return;
			}
			that.stop = $(window).scrollTop();
			that.bodyScrollStop = true;
			if (!mousewheelTimer)
			{
				mousewheelTimer = setTimeout(function()
				{
					mousewheelTimer = 0;
					that.bodyScrollStop = false;
				}, 500);
			}
		});
		// /////////////////////////////////////////////////////
		$('body').on('click', '.show-tab', function(event)
		{
			var type = $(this).attr('data-type');
			that.runCmd(this.id, null, type);
		});
		$('body').on('click', '.show-tabs', function(event)
		{
			var path = this.id;
			var inLayer = $(this).hasClass('inLayer');
			if (!inLayer)
				that.showTree(path);
			else
				var layerCap = this.textContent || '.';
			that.showTreeToMain(path, '', layerCap);
		});
		// 底部菜单
		$('body').on('click', '.bottommenu ul', function(event)
		{
			if (!this.id)
				this.id = 'm3';
			that.bottomMenu(this.id);
		});
		// 软键盘事件
		$('body').on('click', "#JP_thisjiangpan div", function()
		{
			if ($(this).hasClass('shift'))
			{
				var x = $(this).find('span').html();
				if (x == 'abc')
				{
					if (that.jp.type == 'abc')
						x = 'ABC';
					else
						x = 'abc';
				}
				else if ($(this).hasClass('sys'))
				{
					that.jp('closesys');
					return;
				}
				that.jp(x, that.jp.initvalue, true);
			}
			else if ($(this).hasClass('exit') || $(this).hasClass('enter'))
			{
				that.jp($(this).hasClass('enter') ? 'closeenter' : 'close');
			}
			else
			{
				if ($(this).hasClass('clear'))
				{
					that.jp.initvalue = '';
				}
				else if ($(this).hasClass('backspace'))
				{
					if (that.jp.initvalue.length <= 1)
						that.jp.initvalue = '';
					else if (that.jp.initvalue.length > 1)
						that.jp.initvalue = that.jp.initvalue.substring(0, that.jp.initvalue.length - 1);
				}
				else if ($(this).hasClass('value'))
				{
					var x = $(this).find('span');
					if (x.length > 0)
					{
						x = x[0].innerText;
						that.jp.initvalue += x;
					}
				}
				else if ($(this).hasClass('space'))
				{
					that.jp.initvalue += ' ';
				}
				$('#JP_thisjiangpan .t80 span').html(that.jp.encode(that.jp.initvalue));
				if (that.jp.enterfun)
					that.jp.enterfun(that.jp.initvalue, false, true);
			}
		});
		// mainface 事件
		$('body').on('click', '.mainface a', function()
		{
			if ($(this).hasClass('enter'))
			{
				loginUser.enter();
			}
			else if ($(this).hasClass('more'))
			{
				if ($(this).hasClass('fa-angle-double-left'))
				{
					$('.mainface span.more').show();
					$(this).removeClass('fa-angle-double-left')
					$(this).addClass('fa-angle-double-right')
				}
				else
				{
					$('.mainface span.more').hide();
					$(this).removeClass('fa-angle-double-right')
					$(this).addClass('fa-angle-double-left')
				}
			}
			else if ($(this).hasClass('reg'))
			{
				app.setHome('reg')
			}
			else if ($(this).hasClass('cha'))
			{
				app.setHome('cha')
			}
			else if ($(this).hasClass('login'))
			{
				app.setHome('login')
			}
			else if ($(this).hasClass('logout'))
			{
				login.isLogin(false);
				app.setHome();
			}
		});
		$('body').on('keyup', '.mainface input', function(event)
		{
			if (event.keyCode == 13)
				loginUser.enter();
		});
		$('body').on('click', '.mainface .fa-chevron-down', function(event)
		{
			loginUser.loginUserList(function(v)
			{
				$('.mainface #login_name').val(v);
			});
		});
	}
	leftFun.prototype.isTopHeadNav = function()
	{
		if (app.vm)
			this._topHeadNav = false;
		else
		{
			var w = $('.main-header .navbar-static-top').width();
			var lm = app.getStorage('bodyLeftMenu');
			this._topHeadNav = ((w >= 980 && lm != 'yes') || $('.bottom-header-hidden').length > 0);
		}
		return this._topHeadNav;
	}
	// 初始化
	leftFun.prototype.init = function()
	{
		this._setFunction = [];
		this.navBarList = [];
		this.setReturnFun(null, true);
		$('#roottree').html('');
	}
	/**
	 * 添加一个导航条（顶部）
	 */
	leftFun.prototype.addNavBar = function(id, type, cap, fun, notshow, brefore)
	{
		// 需要先关闭全面屏幕
		if (!app.vm)
			closeFullLayer();
		if (!this.navBarList || arguments.length == 0)
			this.navBarList = [];
		if (cap)
		{
			if (cap.indexOf('<') > 0)
				cap = cap.substring(0, cap.indexOf('<'));
			if (!id)
				id = this.navBarList.length;
			if (!type)
				type = '';
			var a = {
				id : id,
				type : type,
				cap : cap,
				fun : fun
			};
			var find = false;
			// 名称相同类型只能显示一次，且截掉后面的
			for (var i = 0; i < this.navBarList.length; i++)
			{
				if (this.navBarList[i].type == type && type != '')
				{
					find = true;
					this.navBarList[i].cap = cap;
					if (fun)
						this.navBarList[i].fun = fun;
					this.navBarList.length = i + 1;
					break;
				}
			}
			if (!find && type != 'hidehash')
			{
				if (brefore)
					this.navBarList.unshift(a);
				else
					this.navBarList.push(a);
			}
		}
		if (!notshow)
			this.showNavBar();
	}
	/**
	 * 设置主显示高度
	 */
	leftFun.prototype.setWrapperHeight = function()
	{
		var hh = $(window).height();
		if (app.vm)
		{
			hh -= 40;
			var minh = hh;
		}
		else
		{
			var h1 = $('.main-header').outerHeight();
			var h3 = $('.user-panel').outerHeight();
			var h4 = $('#roottree').outerHeight();
			var minh = Math.max(hh - h1, h3 + h4);
		}
		if (minh > 0)
		{
			$(".content-wrapper , .right-side").css("min-height", minh + 'px');
		}
	}
	/**
	 * 显示导航条，返回标题数组
	 */
	leftFun.prototype.showNavBar = function(obj)
	{
		var reCap = [];
		if (obj)
			this.addNavBar();
		if (obj && typeof obj == 'string')
		{
			var path = obj;
			obj = $('#roottree #' + path)[0];
			while (!obj)
			{
				var a = path.split('-');
				if (a.length > 1)
				{
					a.length--;
					path = a.join("-");
					obj = $('#roottree #' + path)[0];
				}
				else
					break;
			}
		}
		if (obj)
		{
			for (var i = 0; i < 32; i++)
			{
				if (!obj || obj.id == 'roottree')
					break;
				if (obj.tagName == 'LI' && obj.id)
				{
					var cap = $(obj).find('span').html();
					reCap.unshift(cap);
					var type = $(obj).attr('data-type');
					if (!type)
						type = 'cmdpath_' + i;
					this.addNavBar(obj.id, type, cap, null, true, true);
				}
				obj = obj.parentNode;
			}
		}
		if (!this.navBarList)
			this.navBarList = [];
		if (this._topHeadNav)
			var swk = $("top-header .headNavBar");
		else
			var swk = $("bottom-header .headNavBar");
		var sw = swk.parent().width() - 80;
		if (sw <= 0)
			sw = '';
		var homename = app.w('home');
		if (app.vm)
		{
			homename = (app.getBusinessName() + ' ').substring(0, 4).trim();
			if (homename.length > 2)
				sw -= (homename.length - 2) * 14;
		}
		var navBar = '';
		navBar += '<li data-level="1" class="selectbusiness" id="top_home"> ' + getIC('dashboard') + ' <span>' + homename + '</span></li>';
		navBar += '<span style="' + (sw ? ('width:' + sw + 'px;') : '') + '" class="k1"><span class="k2">';
		for (var i = 0; i < this.navBarList.length; i++)
		{
			var t = this.navBarList[i];
			var id = t['id'] ? t['id'] : '';
			var type = t['type'] ? (' data-type="' + t['type'] + '"') : '';
			navBar += '<li ' + type + ' data-level="' + (i + 2) + '" id="top_' + id + '">' + t['cap'] + '</li>';
		}
		navBar += '</span></span>';
		if (this._topHeadNav)
			$(".top-header .headNavBar").html(navBar);
		else
			$(".bottom-header .headNavBar").html(navBar);
		if (document.title == 'WTP')
			document.title = app.w('wtp');
		return reCap;
	}
	/**
	 * 添加一个菜单项目 type 为菜单类型，在菜单项中，type必须唯一
	 */
	leftFun.prototype.addMenu = function(fpath, name, caption, icon, type, fun, liclass)
	{
		if (name.indexOf('_') >= 0 || name.indexOf('-') >= 0)
		{
			app.err("命令名称中不能含短线和下划线");
			return '';
		}
		if (fpath && fpath.indexOf('#') < 0)
			fpath = '#' + fpath;
		var path = (fpath ? (fpath + '-') : '') + name;
		path = path.replace(/[\#\.]/g, '');
		if ($('#roottree #' + path).length > 0)
		{
			// 如果path已经存在，则在后面加序号
			path += '_' + this._pathi++;
		}
		if (!type)
			type = '';
		else
			type = ' data-type="' + type + '"';
		var li = '<li id="' + path + '" class="treeview show-tab' + (liclass ? (' ' + liclass) : '') + '" ' + type + '><a>' + getIC(icon) + ' <span class="' + path + '">' + caption + '</span>' + '</a></li>';
		if (!fpath)
		{
			$('#roottree').append(li);
		}
		else
		{
			if ($('#roottree' + ' ' + fpath).length <= 0)
			{
				return;
			}
			var ul = $('#roottree ' + fpath + ' > ul');
			if (ul.length <= 0)
			{
				$('#roottree ' + fpath).append('<ul class="treeview-menu">' + li + '</ul>');
				var a = $('#roottree ' + fpath + ' > a');
				var ap = '<span class="pull-right-container">' + getIC('angle-left pull-right') + '</span>';
				a.append(ap);
				a.attr('data', '');
				$('#roottree ' + fpath).removeClass('show-tab');
			}
			else
			{
				ul.append(li);
			}
		}
		if (fun)
		{
			this.setFunction(path, fun);
		}
		return path;
	}
	/**
	 * 换肤
	 */
	leftFun.prototype.changeFace = function(show, mustShowFace)
	{
		var skin = app.getSkin();
		if (app.isBoard)
		{
			$('body').css('background', 'blue');
			return;
		}
		if (app.vm)
		{
			if (show === false)
				$('body').css('background-image', 'url()');
			return;
		}
		if (show === true)
		{
			if ((!login.isLogin() || mustShowFace) && app.vm)
			{
				var url = 'url(static/' + app.core + '/skin/' + skin + '/images/face0.jpg)';
				$('body').css('background-image', url);
				if (!$('body').hasClass('face'))
					$('body').addClass('face face0');
			}
		}
	}
	/**
	 * 显示主页面
	 */
	leftFun.prototype.showWrapper = function(doShow, notWaitTime)
	{
		var that = this;
		if (doShow)
		{
			that.showWrapper.isShow = true;
			var w = loginUser.getEnterTime();
			if (w > 0 && !notWaitTime)
			{
				setTimeout(function()
				{
					that.showWrapper(true, true);
				}, w);
				return true;
			}
			$('.loadingimage').hide();
			$('div.wrapper').show();
			if (app.vm)
			{
				$('div.bottommenu').removeClass('hidden2');
				if (!$('div.bottommenu').hasClass('hidden'))
					$('div.bottommenu').show();
			}
			if (app.isSinglePage())
			{
				$('.main-header').hide();
				$('.content-header').hide();
				$('.content-header').addClass('hidden');
			}
			$('div.mainface').hide();
			$('.wrapper').css('min-height', $(window).height());
			app.setAppSize();
		}
		return this.showWrapper.isShow;
	}
	/**
	 * 显示屏保
	 */
	leftFun.prototype.showLogoFace = function(isShow, byOption)
	{
		var t = new Date().getTime();
		if (byOption || !this.showLogoFace.lastOptionTime)
		{
			this.showLogoFace.lastOptionTime = t;
			if (this.showLogoFace.isShow)
				this.showLogoFace(false);
			return;
		}
		var ts = t / 1000;
		if (window.login && login.usertoken && login.usertoken.endtime < ts + login.usertoken.expire / 2 && login.usertoken.userid > 0)
		{
			ajax.request('wtp.login.user.refreshToken', {}, function(data, adata, msg, code)
			{
			});
		}
		if (isShow !== true && isShow !== false)
		{
			var inter = app.getInterval();
			if (inter > 0 && t - this.showLogoFace.lastOptionTime > inter * 3)
			{
				this.showLogoFace(true);
			}
		}
		else
		{
			var k = $('#_showLogoFace');
			if (k.length > 0)
			{
				if (isShow)
					k.show();
				else
					k.hide();
			}
			else if (isShow)
			{
				if (!login.isLogin())
					return app.setHome();
				else
				{
					if (!this.faceN && !app.vm)
					{
						var t = new Date();
						var day = t.getFullYear() * 366 + t.getMonth() * 31 + t.getDate();
						var moth = t.getFullYear() * 12 + t.getMonth();
						var i = Math.floor(day / 7);
						this.faceN = getRand(1, 31, moth, i);
					}
					else
						this.faceN = 0;
					var h = ($(window).height() - 200) / 2;
					var s = '<div id="_showLogoFace" style="background-color:#0e6e8c;z-index:999999999;background-size:100% 100%;position:fixed;top:0;left:0;right:0;bottom:0;';
					s += 'background-image:url(static/' + app.core + '/skin/' + app.getSkin() + '/images/face' + this.faceN + '.jpg)">';
					s += '<img style="display:block;margin:' + h + 'px auto 24px auto" src="static/' + app.core + '/skin/' + app.getSkin() + '/images/logo.png">';
					s += '<div style="text-align:center;font-size: 36px; font-weight: 900; text-shadow: #fff 1px 0 0, #fff 0 1px 0, #fff -1px 0 0, #fff 0 -1px 0; color: #000;">智力库</div>';
					s += '</div>';
					$('body').append(s);
				}
			}
			this.showLogoFace.lastOptionTime = t;
			this.showLogoFace.isShow = isShow;
		}
	}
	/**
	 * 是否显示登录页面
	 */
	leftFun.prototype.isShowFace = function()
	{
		var k = $('.mainface');
		if (k.length > 0 && !k.is(':hidden'))
			return true;
		return false;
	}
	/**
	 * 执行显示登陆界面
	 */
	leftFun.prototype.showFace = function(ishsow, mustShowFace)
	{
		if (ishsow)
		{
			$('div.wrapper').hide();
			$('div.layui-layer').hide();
			$('div.mainface').show();
			$('body').addClass('overflowhidden');
			this.changeFace(true, mustShowFace);
			this.showBottom(false);
		}
		else
		{
			layer.closeAll();
			if (!app.isSinglePage())
				$('div.layui-layer').show();
			$('div.mainface').remove();
			$('body').removeClass('overflowhidden');
			$('body>div.mainface').remove();
			this.changeFace(false, mustShowFace);
			this.showBottom(true);
		}
	}
	/**
	 * 显示登陆界面
	 */
	leftFun.prototype.face = function(isclose, logintype, must)
	{
		if (isclose)
		{
			this.showFace(false);
			return;
		}
		if (!logintype)
		{
			if (!must && this.face.inLogin)
			{
				if ($('div.mainface').length > 0)
					return;
			}
		}
		this.face.inLogin = !logintype;
		$('body').css('min-height', $(window).height() + 'px');
		var that = this;
		if ((!login.isLogin() && logintype == 'about') || !logintype)
			logintype = '';
		layer.closeAll();
		var lang = '';
		lang = app.getLangName();
		var lancap = '';
		var skin = app.getSkin();
		var ol = '';
		if (app.vm && logintype == 'about')
			ol = ' onclick="loginUser.enter()" ';
		var hh = '';
		var t = '<div class="title loginbox_32 bb"><img ' + ol + ' class="logo" src="./static/' + app.core + '/skin/' + skin + '/images/logo.png">';
		t += '<p class="p1">' + app.getWtpCaption();
		t += '<p class="p2">' + getCurVersion(true);
		var cap = login.isLogin() ? app.w('Enter') : app.w('login');
		t += '<div class="input">';
		if (!login.isLogin())
		{
			t += getIC('chevron-down');
			t += '<p class="p3 login" style="' + (app.isBoard ? 'display:none' : '') + '">' + (logintype == 'reg' ? app.w('ChineseUserName') : app.w('UserName')) + ' : <input id="login_name" value="' + (app.isBoard ? '' : app.getUserName()) + '">';
			t += '<p class="p3 login">' + app.w('passWord') + ' : <input type="password" oninput="left.inputPassword(this)" onpropertychange="left.inputPassword(this)" class="password" id="password">';
			if (logintype == 'reg')
			{
				t += '<p class="p3 login">' + app.w('retypePassword') + ' : <input type="password" id="password2">';
				t += '<p class="p3 login">' + app.w('inviteCode') + ' : <input class="password" type="password" id="invitecode">';
				cap = app.w('signup');
			}
			else if (logintype == 'cha')
			{
				t += '<p class="p3 login">' + app.w('newPassword') + ' : <input class="password" type="password" id="password1">';
				t += '<p class="p3 login">' + app.w('retypePassword') + ' : <input class="password" type="password" id="password2">';
				cap = app.w('changePassword');
			}
			t += '<input type="hidden" id="logintype" value="' + logintype + '">';
		}
		t += '<p class="p3 textcenter">';
		if (logintype != 'about')
		{
			t += getIC('angle-double-left more', 'a');
			// 隐藏部分
			t += '<span class="more" style="display:none">';
			if (!app.isSinglePage() && !login.isLogin())
			{
				if (logintype != 'reg')
					hh += '<a class="reg" >' + app.w('SignUp') + '</a>';
				if (logintype != 'cha')
					hh += '<a class="cha" >' + app.w('ChangePassword') + '</a>';
			}
			else if (login.isLogin())
			{
				hh += '<a class="logout">' + app.w('SignOut') + '</a>';
			}
			if (logintype && logintype != 'login')
				hh += '<a class="login" >' + app.w('SignIn') + '</a>';
			if (app.vm)
				hh += lancap;
			t += hh;
			t += '</span>';
			// 隐藏部分结束
			if (!app.vm)
				t += lancap;
			else
				t += ' &nbsp; &nbsp; ';
		}
		t += '<a class="enter">' + cap + '</a></div>';
		t += '</div>';
		if (!login.isLogin())
		{
			t += that.getWeiXinLoginHtml(logintype);
		}
		if (!app.vm)
			t += '<p class="hh">' + hh + '<a href="https://docs.witopen.com" target="_blank">' + app.w('openapi') + '</a></p>';
		if ($('.mainface').length > 0)
			$('.mainface').html(t);
		else
		{
			var st = app.vm ? '' : 'top:-8080px;height:600px;';
			$('body').append('<div class="mainface a0" style="' + st + '">' + t + '</div>');
		}
		$('.loadingimage').hide();
		this.showFace(true, logintype == 'about');
		app.setAppSize();
		setTimeout(function()
		{
			$('.mainface .password').val('');
		}, 1000);
		if (window.toAndroidApp)
		{
			var setIntervalIndex = 0;
			var that = this;
			setIntervalIndex = setInterval(function()
			{
				if (login.isLogin() || !that.isShowFace() || !window.toAndroidApp.tryGetFinger)
				{
					clearInterval(setIntervalIndex);
					return;
				}
				window.toAndroidApp.tryGetFinger();
			}, 1000);
		}
	}
	leftFun.prototype.getWeiXinLoginHtml = function(logintype, boxId, backfun, show, justTestUserId)
	{
		var that = this;
		$('.mainface div.wx_login_box').remove();
		// 显示微信登录二维码
		var ua = navigator.userAgent.toLowerCase();
		var href = window.location.href;
		var top = logintype === false ? -1 : (!logintype || logintype == 'login' ? 180 : 248);
		if (ua.match(/MicroMessenger/i) == "micromessenger" && app.vm)
		{
			// 是处于微信中
			// 查看是不是已经登录
			var info = '';
			var kw = '&wxloginInfo=';
			if (href.indexOf(kw) > 0)
			{
				var i = href.indexOf(kw);
				info = decodeURIComponent(href.substring(i + kw.length));
			}
			else
			{
				info = localStorage.getItem('wxloginInfo');
			}
			if (info)
			{
				localStorage.removeItem('wxloginInfo');
				info = JSON.parse(info);
				if (info && info.unionid && info.time && new Date().getTime() - info.time < 30000)
				{
					that.loginByWxUnionid(info.unionid, info.state, info.sign, null, info.header, info.nickname);
				}
			}
			var state = href;
			var i = state.indexOf('##');
			if (i > 0)
				state = state.substring(0, i);
			state = state + '##' + Math.random();
			var url = 'https://open.weixin.qq.com/connect/oauth2/authorize?response_type=code&scope=snsapi_userinfo&state=' + encodeURIComponent(state);
			url += '&appid=' + config.wxAppId2;
			url += '&redirect_uri=' + encodeURIComponent(config.wxRedirectUri2);
			url += '#wechat_redirect';
			var t = '<div class="wx_login_box wxcmd" style="display:none;background:rgba(0, 0, 0, 0);"><a href="' + url + '"><i class="fa fa-weixin white"> ' + app.w('wxlogin') + '</i></a></div>';
			setTimeout(function()
			{
				$('.mainface div.wx_login_box').show();
			}, 1);
		}
		else
		{
			boxId = boxId || 'wx_login_container';
			var t = '<div style="display:' + (show ? '' : 'none') + '" class="wx_login_box"><div id="' + boxId + '"></div><p>' + app.w('wxloginscan') + '</p></div>';
			setTimeout(function()
			{
				that.getWeiXinCode(top, boxId, backfun, justTestUserId);
			}, 1);
		}
		return t;
	}
	/**
	 * 生成微信登录二维码
	 */
	leftFun.prototype.getWeiXinCode = function(top, boxId, backfun, justTestUserId)
	{
		var that = this;
		that.getWeiXinCode.backfun = backfun;
		that.getWeiXinCode.justTestUserId = justTestUserId || 0;
		loadJs('https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js', function()
		{
			var href = window.location.href;
			var i = href.indexOf('.com');
			if (i <= 0)
				return;
			href = href.substring(0, i + 4) + '/static/' + app.core + '/css/public/wx.css?r=9';
			href = href.replace('http://admin.wtp.com/static/' + app.core, 'https://testadmin.witopen.com/static/coreA');
			href = encodeURIComponent(href);
			var uri = encodeURIComponent(config.wxRedirectUri);
			boxId = boxId || 'wx_login_container';
			var obj = new WxLogin({
				self_redirect : true,
				id : boxId,
				appid : config.wxAppId,
				scope : 'snsapi_login',
				redirect_uri : uri,
				state : 'S' + Math.random() + 'E',
				href : href
			});
			if (!that.getWeiXinCode.haveListen)
			{
				that.getWeiXinCode.haveListen = true;
				// 监听接收信息(可能来自iframe)
				window.addEventListener("message", function(e)
				{
					var res = e;
					var data = e.data;
					var info = e.data.info;
					switch (data.action)
					{
					case 'wxlogin':
						$('.mainface div.wx_login_box').hide();
						var backfun = that.getWeiXinCode.backfun;
						var justTestUserId = that.getWeiXinCode.justTestUserId;
						if (info.unionid)
						{
							if (justTestUserId > 0)
							{
								ajax.request('wtp.login.user.testWxUnionId', {
									unionid : info.unionid,
									userId : justTestUserId
								}, function(data, adata, msg, code)
								{
									if (backfun)
										backfun();
								});
							}
							else
								that.loginByWxUnionid(info.unionid, info.state, info.sign, backfun, info.header, info.nickname);
						}
						break;
					default:
						return;
					}
				});
			}
		});
		$('.mainface div.wx_login_box').show();
		if (top >= 0)
		{
			if (app.vm)
			{
				$('.mainface div.wx_login_box').css('top', top + 'px');
				$('.mainface div.wx_login_box').css('left', ($(window).width() / 2 - 80) + 'px');
			}
			else
			{
				// if ($('.mainface div.title').length > 0)
				// {
				// var titleLeft = $('.mainface div.title').offset().left;
				// if (titleLeft + 200 < $(window).width() / 2)
				// $('.mainface div.wx_login_box').css('right', '6px');
				// else
				// $('.mainface div.wx_login_box').css('left', '6px');
				// }
			}
		}
	}
	leftFun.prototype.loginByWxUnionid = function(unionid, state, sign, backfun, hearder, nickname)
	{
		var that = this;
		that.loginByWxUnionid.info = null;
		if (!unionid)
			return;
		ajax.request('wtp.login.user.login', {
			unionid : unionid,
			state : state,
			sign : sign
		}, function(data, adata, msg, code)
		{
			if (code == 0)
			{
				if (backfun)
					backfun()
				else
					loginUser.afterLogin();
			}
			if (code == -1) // 首次绑定，需要用户名和密码
			{
				that.loginByWxUnionid.info = {
					unionid : unionid,
					state : state,
					sign : sign
				};
				var s = app.w('login.msg.inputNameAndPassWordForFirstLogin');
				confirm(s, function()
				{
					var html = '<div style="text-align:center;width:140px"><p style="margin:4px 0">' + s + '</p>';
					if (nickname)
						html += '<img style="width:48px;height:48px;margin:auto" src="' + hearder + '"> <p>' + nickname + '</p>';
					html += '<p style="margin:12px 0" onclick="left.loginByWxUnionid();app.reload()"><a>' + app.w('cancel') + '</a></p></div>';
					$('.mainface div.wx_login_box').html(html);
					$('.mainface div.wx_login_box').show();
				}, function()
				{
					app.reload();
				});
			}
		}, null, true);
	}
	leftFun.prototype.inputPassword = function(obj, getValue)
	{
		if (app.isBoard)
		{
			return $(obj).val();
		}
		var pw = $(obj).attr('pw') || '';
		if (getValue)
		{
			var password = $(obj).val();
			password = pw + password.replace(/\|/g, '');
			$(obj).val(password ? 'I cannot let you see my password' : '');
			return password;
		}
		var va = $(obj).val();
		pw = pw.substring(0, va.length);
		var vn = va.replace(/\|/g, '');
		if (va == vn)
			pw = vn;
		else
			pw += vn;
		var x = '';
		for (var i = 1; i <= 32; i++)
			x += '||';
		$(obj).val(x.substring(0, pw.length));
		$(obj).attr('pw', pw);
	}
	leftFun.prototype.setToPc = function()
	{
		if (app.whith >= 600)
			return;
		app.PcModel = !app.PcModel;
		app.setStorage('PcModel', app.PcModel ? 'yes' : 'no');
		app.reload();
	}
	/**
	 * 底部设置菜单，当id为false时，表示清空列表
	 */
	leftFun.prototype.startMenu = function(id)
	{
		if (id === false)
		{
			return;
		}
		if (!app.vm)
			return;
		var that = this;
		// 遍历快捷方式
		if (id)
		{
			if (id == 'tools')
				this.goPage('login-tools');
			else if (id == 'forceRefresh')
				app.readVersion(true, null, true, true);
			else if (id == 'refreshToken')
				login.refreshToken(0, false, true);
			else if (id == 'setToPc')
				this.setToPc();
			else if (id == 'about')
				app.setHome('about');
			else if (id == 'nokeyboard')
			{
				var need = app.needWTPJp();
				app.needWTPJp(!need);
				var k = $('.icons .dataTables_wrapper .fa-keyboard-o');
				k.removeClass('af af-yellow af-ban');
				if (!need)
					k.addClass('af af-yellow af-ban');
				k.parent().find('span').html(!need ? app.w('openSysKeyboard') : app.w('closeSysKeyboard'));
			}
			else if (id == 'exit')
			{
				login.logOut(null, false, false, true);
			}
			else if (id.indexOf('-') > 0)
			{
				this.runCmd(id);
			}
			return;
		}
		var le = this.navBarList ? this.navBarList.length : 0;
		var needWTPJp = app.needWTPJp();
		var d = [ {
			id : 'nokeyboard',
			cap : getIC('keyboard-o blue autobbcolor' + (needWTPJp ? ' af af-yellow af-ban' : '')) + '<span>' + (needWTPJp ? app.w('openSysKeyboard') : app.w('closeSysKeyboard')) + '</span>'
		}, {
			id : 'exit',
			cap : getIC('sign-out blue autobbcolor') + '<span>' + app.w('logout') + '</span>'
		}, {
			id : 'forceRefresh',
			cap : getIC('rotate-right blue autobbcolor') + '<span>' + app.w('forceRefresh') + '</span>'
		}, {
			id : 'refreshToken',
			cap : getIC('exchange blue autobbcolor') + '<span>' + app.w('refreshToken') + '</span>'
		}, {
			id : 'about',
			cap : getIC('slideshare blue autobbcolor') + '<span>' + app.w('about') + '</span>'
		} ];
		if (login.haveAuth('login', 'P'))
		{
			var ic = app.m ? 'television' : 'hdd-o';
			d.push({
				id : 'setToPc',
				cap : getIC(ic + ' blue autobbcolor') + '<span>' + (app.m ? app.w('setToPc') : app.w('setToM')) + '</span>'
			});
		}
		if (this.thisSettingLayerIndex)
		{
			var li = this.thisSettingLayerIndex;
			setTimeout(function()
			{
				layer.close(li);
			}, 500);
		}
		var margin = 0;
		if (app.vm)
			margin = Math.floor(($(window).width() - 5 * 60) / 6);
		var lis = '';
		for (var i = 0; i < d.length; i++)
		{
			lis += '<ul role="row" class="odd" style="margin:0 0 0 ' + margin + 'px" onclick="left.startMenu(\'' + d[i].id + '\')" ><li class="show-tab">' + d[i].cap + '</li></ul>';
		}
		this.thisSettingLayerIndex = this.showTreeToMain('login', lis, app.w('set'));
	}
	/**
	 * 到上一页 , holdn 保留层级（0）为不保留
	 */
	leftFun.prototype.goBack = function(holdn, isTry, backfun)
	{
		var that = this;
		if (!this.okToChangeMain())
		{
			this.okToChangeMain(function()
			{
				that.goBack(holdn, isTry, backfun);
			});
			return;
		}
		var pa = that.navBarList;
		if (pa && pa.length <= 0)
		{
			this.refreshNavBar();
			/*
			 * that.navBarList = []; var objk = $('.headNavBar .k2 li:last'); var obj = null; if (objk.length > 0) { var id = (objk[0].id + '').substring(4); var objk = $('#roottree #' + id); if (objk.length > 0) obj = objk[0]; } for (var i = 0; i < 32; i++) { if (!obj || obj.id == 'roottree') break; if (obj.tagName == 'LI' && obj.id) { var cap = $(obj).find('span').html(); var type = $(obj).attr('data-type'); if (!type) type = 'cmdpath_' + i; this.addNavBar(obj.id, type, cap, null, true, true); } obj = obj.parentNode; }
			 */
			if (that.navBarList.length > 0)
			{
				return that.goBack(holdn, isTry, backfun, true);
			}
		}
		if (!pa)
		{
			if (!isTry)
				that.goPage('');
			if (backfun)
				backfun();
			return true;
		}
		if (holdn > 0 && pa.length <= holdn)
		{
			if (backfun)
				backfun();
			return false;
		}
		var backn = 1;
		if (backn >= pa.length)
		{
			if (!isTry)
				that.goPage('');
			if (backfun)
				backfun();
			return true;
		}
		else
		{
			var i = pa.length - 2;
			if (i >= 0)
			{
				if (isTry)
				{
					if (backfun)
						backfun();
					return true;
				}
				if (false === that.runHeadNav(pa[i].id, i + 2))
					return that.goBack(0, isTry, backfun, true);
				else
				{
					if (backfun)
						backfun();
					return true;
				}
			}
			else
			{
				if (!isTry)
					that.goPage('');
				if (backfun)
					backfun();
				return true;
			}
		}
	}
	leftFun.prototype.refreshNavBar = function()
	{
		this.navBarList = [];
		var objk = $('.headNavBar .k2 li:last');
		var obj = null;
		if (objk.length > 0)
		{
			var id = (objk[0].id + '').substring(4);
			var objk = $('#roottree #' + id);
			if (objk.length > 0)
				obj = objk[0];
		}
		for (var i = 0; i < 32; i++)
		{
			if (!obj || obj.id == 'roottree')
				break;
			if (obj.tagName == 'LI' && obj.id)
			{
				var cap = $(obj).find('span').html();
				var type = $(obj).attr('data-type');
				if (!type)
					type = 'cmdpath_' + i;
				this.addNavBar(obj.id, type, cap, null, true, true);
			}
			obj = obj.parentNode;
		}
	}
	/**
	 * 到某页
	 */
	leftFun.prototype.goPage = function(path, fromhash, failedToHome, byHand, mustTry)
	{
		var that = this;
		if (!this.okToChangeMain())
		{
			var isOk = this.okToChangeMain(function(isOk)
			{
				if (isOk)
					that.goPage(path, fromhash, failedToHome, byHand, mustTry);
			});
			if (!isOk)
				return false;
		}
		if (path && path.length > 256 || (path && path.indexOf(':') >= 0))
			path = '';
		// 不能再极短时间内连续执行两次
		var tm = (new Date()).getTime();
		if (!failedToHome)
		{
			if (!app.haveInit || (this._lasthashpath == path && fromhash) || (this._lastgopagetime > 0 && tm - this._lastgopagetime < 333))
				return false;
		}
		this._lastgopagetime = tm;
		// /////////////////////////
		if (!app.vm)
			closeFullLayer();
		this._lasthashpath = path;
		if (path == 'home' || !path)
		{
			this.navBarList = [];
			app.setHome('', byHand);
			return true;
		}
		// 遍历回去
		var pa = path.split('-');
		while (path)
		{
			if ((path + ' ').indexOf('.') >= 0)
				break;
			var sv = $('#roottree #' + path);
			if (sv.hasClass('show-tab'))
			{
				this.runCmd(path);
				return true;
			}
			else if (sv.hasClass('treeview'))
			{
				this.showTreeToMain(path);
				return true;
			}
			else if (path && path.indexOf('_') < 0 && mustTry)
			{
				return false;
			}
			// //////////////////////
			if (pa.length > 1)
			{
				pa.length--;
				path = pa.join('-');
			}
			else
			{
				this.addNavBar();
				if (app.vm && !failedToHome)
				{
					return this.goPage('', fromhash, true, byHand, mustTry, true);
				}
				app.setHome('', byHand);
				return true;
			}
			return false;
		}
	}
	/**
	 * 执行某个命令
	 */
	leftFun.prototype.runCmd = function(path, fun, type)
	{
		if (!path || !app.haveInit)
			return;
		var that = this;
		if (!this.okToChangeMain())
		{
			this.okToChangeMain(function()
			{
				that.runCmd(path, fun, type);
			});
			return;
		}
		// 取得参数
		var cc = $('#roottree #' + path);
		if (cc.hasClass('show-tab'))
		{
			// 执行命令，先设置服务
			var a = path.split('-');
			if (a[0])
				ajax.setServerName(a[0]);
			if (fun)
			{
				fun(path);
			}
			else
			{
				if (this._setFunction[path])
				{
					fun = this._setFunction[path];
					if (typeof type == 'undefined')
					{
						type = cc.attr('data-type');
					}
					if (type && type.indexOf('data-') === 0)
						var p = type.substring(5);
					else
						p = '';
					if (fun)
						fun(path);
				}
				else
				{
					// app.err('没有定义功能：' + path);
				}
			}
			if (type == 'hidehash')
				return;
			// 显示相应的路径
			var reCap = this.showNavBar(cc[0]);
			// 展开
			this.showTree(path);
			// 关闭所有弹出框
			if (!app.vm)
				closeFullLayer();
		}
	}
	/**
	 * 显示当前树
	 */
	leftFun.prototype.showTree = function(path)
	{
		if (!login || !login.isLogin())
			return;
		$('#roottree').find('li').each(function()
		{
			var p = this.parentNode;
			if (p && p.tagName == 'UL' && p.id != 'roottree')
				p.style.display = 'none';
			$(this).removeClass('active');
			$(this).removeClass('actives');
		});
		url = window.location.href;
		var i2 = url.indexOf('#');
		if (i2 > 0)
			url = url.substring(0, i2);
		if (path !== 'home' && path)
		{
			window.history.replaceState(null, null, url + '#_' + path);
			this._lasthashpath = path;
			var a = path.split('-');
			var id = '';
			for (var i = 0; i < a.length; i++)
			{
				id += (id ? '-' : '') + a[i];
				$('#roottree #' + id).addClass('active');
				$('#roottree #' + id).addClass('actives');
				if (!app.haveNote)
					$('#roottree #' + id).parent().css('display', 'block');
			}
		}
		else
		{
			window.history.replaceState(null, null, url + '#');
			this._lasthashpath = path;
		}
	}
	/**
	 * 在右边显示左边的菜单
	 */
	leftFun.prototype.showTreeToMain = function(path, addHtml, layerCap, justReturnHtml)
	{
		if (app.isSinglePage())
			return 0;
		var lis = '';
		if (path)
			var kk = $('#' + path).children("ul:first");
		else
		{
			var kk = $('#roottree');
			closeFullLayer();
		}
		var margin = 0;
		if (app.vm)
			margin = Math.floor(($(window).width() - 5 * 60) / 6);
		var that = this;
		var justonePath = app.vm ? null : false;
		addHtml = addHtml || '';
		kk.children('li').each(function()
		{
			var id = $(this).attr('id');
			if (!id)
				return 0;
			var clalii = 'cmd ' + $(this).find('a i').attr('class');
			var caption = $(this).find('span').html();
			if ($(this).hasClass('show-tab'))
			{
				var clali = ' show-tab';
				clalii += ' blue';
			}
			else
			{
				var clali = ' show-tabs';
				clalii += ' yellow';
				justonePath = false;
				if (path && app.vm)
				{
					var lisi = that.showTreeToMain(id, '', '', true);
					if (lisi)
					{
						if (!justReturnHtml)
							addHtml += '<div class="subicons"><p>' + caption + '</p>' + lisi + '</div>';
						else
							addHtml += lisi;
						return;
					}
				}
			}
			if (layerCap)
				clali += ' inLayer';
			var type = $(this).attr('data-type');
			if (!type)
				type = '';
			else
				type = 'data-type="' + type + '"';
			var fa = getIC(clalii + ' autobbcolor');
			lis += '<ul role="row" class="odd" style="margin:0 0 0 ' + margin + 'px"><li id="' + id + '"' + type + ' class="' + clali + '">' + fa + '<span>' + caption + '</span></li></ul>';
			if (justonePath === null)
				justonePath = id;
			else
				justonePath = false;
		});
		lis += addHtml;
		if (justReturnHtml)
			return lis;
		if (justonePath)
		{
			left.runCmd(justonePath);
			return;
		}
		if (layerCap)
		{
			var html = '<div class="icons desk leftStartMenu"><div class="dataTables_wrapper">' + lis + '</div></div>';
			return showFullLayer(layerCap, html, null, false, 0, '', false, null, null, 0, null, true);
		}
		else
		{
			this.showNavBar(path);
			this.setMainContentHtml(lis, null, false, true, null, false, !path || path == 'home', null, true);
		}
		return 0;
	}
	// 注册命令
	leftFun.prototype.setFunction = function(path, fun)
	{
		this._setFunction[path] = fun;
	}
	/**
	 * 显示底部菜单
	 */
	leftFun.prototype.showBottom = function(isShow)
	{
		if (!app.vm || app.isSinglePage())
			isShow = false;
		if (isShow)
		{
			var bName = app.getBusinessName(true);
			$('div.bottommenu .m2 span').html(bName);
			// 查看是不是只有一个功能
			var sei = 0;
			for ( var k in app.servers)
			{
				if (k != 'login')
				{
					sei++;
					if (sei > 1)
						break;
				}
			}
			if (this.showBottom.sei === sei)
				return;
			this.showBottom.sei = sei;
			if (!$('div.bottommenu .m1 span').html())
			{
				$('div.bottommenu .m2 span').html(bName);
				$('div.bottommenu .m4 span').html(app.w('login.bottommenu.Refresh'));
				$('div.bottommenu .m5 span').html(app.w('login.bottommenu.setting'));
			}
			$('div.bottommenu .m1 span').html(app.w('home'));
			$('div.bottommenu').removeClass('hidden');
			if (!$('div.bottommenu').hasClass('hidden2'))
				$('div.bottommenu').show();
		}
		else
		{
			$('div.bottommenu').addClass('hidden');
			this.showBottom.sei = null;
		}
	}
	/**
	 * 底部菜单运行
	 */
	leftFun.prototype.bottomMenu = function(id)
	{
		if (id == 'm1')
		{
			this.goPage('');
		}
		else if (id == 'm2')
		{
			app.selectBusiness(null, true);
		}
		else if (id == 'm3')
		{
			if (!closeFullLayer(0, false, true))
			{
				var pn1 = this.navBarList && this.navBarList.length > 0 ? this.navBarList.length : 0;
				var that = this;
				this.goBack(0, 0, function()
				{
					var pn2 = that.navBarList && that.navBarList.length > 0 ? that.navBarList.length : 0;
					that.bottomMenu.upNumber = that.bottomMenu.upNumber || 0;
					if (pn1 == pn2)
					{
						that.bottomMenu.upNumber++;
						if (that.bottomMenu.upNumber >= 4)
						{
							confirm(app.w('login.msg.areYouSureLogout'), function()
							{
								login.logOut(null, false, false, true);
							})
							that.bottomMenu.upNumber = 0;
						}
					}
					else
						that.bottomMenu.upNumber = 0;
				});
			}
		}
		else if (id == 'm4')
		{
			loginWorktask.readTasktypeNew();
		}
		else if (id == 'm5')
		{
			this.startMenu();
		}
		else
			return;
		var kk = $('div.bottommenu ul i');
		kk.removeClass('yellow');
		kk.addClass('blue');
		var k = $('div.bottommenu .' + id + ' i');
		k.removeClass('blue');
		k.addClass('yellow');
		var havew = false;
		setTimeout(function()
		{
			k.removeClass('yellow');
			k.addClass('blue');
		}, 5000);
	}
	/**
	 * 软键盘
	 */
	leftFun.prototype.jp = function(type, initvalue, enterfun, setsysjpfun, password)
	{
		if (type == 'close' || type == 'closeenter' || type == 'closesys' || arguments.length == 0)
		{
			layer.close(this.jp.layerIndex);
			if (type == 'closeenter')
			{
				if (this.jp.enterfun)
					this.jp.enterfun(this.jp.initvalue, true);
			}
			else if (type == 'closesys')
			{
				if (this.jp.setsysjpfun)
					this.jp.setsysjpfun();
			}
			return;
		}
		if (!app.needWTPJp())
			return;
		if (password != undefined)
			this.jp.password = password;
		var that = this;
		if (!this.jp.encode)
		{
			this.jp.encode = function(t)
			{
				if (that.jp.password)
					t = ('*****************************************').substring(0, t.length);
				else
				{
					t = t.replace(/\s/g, '&nbsp;');
					t = t.replace(/</g, '&lt;');
					t = t.replace(/>/g, '&gt;');
				}
				t += '<font class="gb">&nbsp;</font>';
				return t;
			};
		}
		if (typeof enterfun == 'function')
			this.jp.enterfun = enterfun;
		if (typeof setsysjpfun == 'function')
			this.jp.setsysjpfun = setsysjpfun;
		if (!initvalue)
			initvalue = '';
		this.jp.initvalue = initvalue;
		if (!type)
		{
			if ($('#JP_thisjiangpan').length > 0)
				return;
		}
		if (!this.jp.oldAbcType)
			this.jp.oldAbcType = 'abc';
		if (!this.jp.old123Type)
			this.jp.old123Type = '123';
		if (!this.jp.oldType)
			this.jp.oldType = 'abc';
		if (!type)
		{
			this.jp.type = this.jp.oldType;
		}
		else if (type == 'abc' || type == 'ABC')
		{
			if (this.jp.oldType == 'abc' || this.jp.oldType == 'ABC')
				this.jp.type = this.jp.oldAbcType == 'abc' ? 'ABC' : 'abc';
			else
				this.jp.type = this.jp.oldAbcType;
			this.jp.oldAbcType = this.jp.type;
		}
		else if (type == '123' || type == '@#$')
		{
			if (this.jp.oldType == '123' || this.jp.oldType == '@#$')
				this.jp.type = this.jp.old123Type == '123' ? '@#$' : '123';
			else
				this.jp.type = this.jp.old123Type;
			this.jp.old123Type = this.jp.type;
		}
		else
			this.jp.type = type;
		type = this.jp.type;
		this.jp.oldType = type;
		var cla = '';
		// //////
		var t = '<div class="t80"><span>' + this.jp.encode(initvalue) + '</span></div>';
		t += '<div class="t20 exit"><span class="s blue">' + app.w('Close') + '</span></div>';
		if (type == 'abc' || type == 'ABC')
		{
			var s = 'QWERTYUIOPASDFGHJKLZXCVBNM';
			if (type == 'abc')
			{
				s = s.toLowerCase();
			}
			cla = 'c123';
			for (var i = 0; i < s.length; i++)
			{
				if (i == 10)
					t += '<div class="t5"></div>';
				if (i == 19)
					t += '<div class="t15 clear"><span class="s blue">' + app.w('clear') + '</span></div>';
				t += '<div class="value"><span>' + s.substring(i, i + 1) + '</span></div>';
			}
			t += '<div class="t15 backspace longpress jp-backspace"><span class="s blue">' + getIC('backward', 'font') + '</span></div>';
		}
		else if (type == '123')
		{
			s = '*123-#456.789';
			for (var i = 0; i < s.length; i++)
			{
				if (i == 10)
					t += '<div class="t20 clear"><span class="s blue">' + app.w('clear') + '</span></div>';
				t += '<div class="t20 value"><span>' + s.substring(i, i + 1) + '</span></div>';
			}
			t += '<div class="t20 backspace longpress jp-backspace"><span class="s blue">' + getIC('backward', 'font') + '</span></div>';
		}
		else if (type == '@#$')
		{
			s = '!@#$%^&*():;{}[]|\\/?,.<>=_';
			for (var i = 0; i < s.length; i++)
			{
				if (i == 20)
					t += '<div class="t20 clear"><span class="s blue">' + app.w('clear') + '</span></div>';
				t += '<div class="value"><span>' + s.substring(i, i + 1) + '</span></div>';
			}
			t += '<div class="t20 backspace longpress jp-backspace"><span class="s blue">' + getIC('backward', 'font') + '</span></div>';
		}
		t += '<div class="t20 shift sys"><span class="s blue">' + app.w('sys') + '</span></div>';
		if (type == 'ABC' || type == 'abc')
		{
			var v = this.jp.oldAbcType;
			var vj = this.jp.oldAbcType == 'abc' ? 'fa-arrow-up' : 'fa-arrow-down';
		}
		else
		{
			var v = this.jp.oldAbcType == 'abc' ? 'abc' : 'ABC';
			var vj = '';
		}
		t += '<div class="t20 shift ' + (type == 'abc' || type == 'ABC' ? 'cur' : '') + '">' + getIC(vj + ' s blue', 'span', '', v) + '</div>';
		if (type == '123')
			t += '<div class="t20 value"><span>0</span></div>';
		else
			t += '<div class="t20 space"><span> </span></div>';
		if (type == '@#$' || type == '123')
			var v = this.jp.old123Type;
		else
			var v = this.jp.old123Type == '123' ? '123' : '@#$';
		t += '<div class="t20 shift ' + (type == '@#$' || type == '123' ? 'cur' : '') + '"><span class="s blue">' + v + '</span></div>';
		t += '<div class="t20 enter"><span class="s blue">' + app.w('ok') + '</span></div>';
		if ($('#JP_thisjiangpan').length > 0)
			$('#JP_thisjiangpan').html(t);
		else
		{
			t = '<div id="JP_thisjiangpan" class="' + cla + '">' + t + '</div>';
			this.jp.layerIndex = layer.open({
				type : 1,
				title : '',
				offset : [ ($(window).height() - 240) + 'px', 0 ],
				area : [ $(window).width() + 'px', '240px' ],
				closeBtn : 0,
				anim : 2,
				shadeClose : true,
				skin : 'JP_thisjiangpan',
				content : t,
				zIndex : 20409999,
				end : function()
				{
					that.jp.layerIndex = -1;
				},
			});
		}
	}
	/**
	 * 调入软键盘
	 */
	leftFun.prototype.loadJp = function(input)
	{
		this.jp(input.type == 'number' ? '123' : '', input.value, function(v, is13, justsetvalue)
		{
			input.value = v;
			if (justsetvalue)
				return;
			while (is13 && app.mainInputObjId && $('#' + app.mainInputObjId).length == 0)
			{
				app.setMainInputObj();
			}
			if (is13 && app.mainInputObjId && $('#' + app.mainInputObjId).length > 0 && input.id == app.mainInputObjId)
			{
				if (app.mainInputSubmitFun)
				{
					v = (v + ' ').trim();
					app.mainInputSubmitFun(v);
				}
			}
			else if (is13)
			{
				(new cmdFun).submitInput(input, true);
			}
			input.focus();
		}, function()
		{
			input.readOnly = false;
			setTimeout(function()
			{
				$(input).focus();
			}, 100);
		}, $(input).hasClass('password'));
	}
	/**
	 * 最顶部菜单
	 */
	leftFun.prototype.rightTopMenu = function(must)
	{
		if (app.isSinglePage() && !must)
			return;
		// 布局
		// var ll = '';
		// var f = app.bodyMax();
		// ll += '<li><a class="fa ' + (f ? 'fa-circle' : 'fa-circle-o') + '" onclick="app.bodyMax(true)" >' + app.w('fullbody') + '</a></li>';
		// ll += '<li class="hr" ><a class="fa ' + (!f ? 'fa-circle' : 'fa-circle-o') + '" onclick="app.bodyMax(false)" >' + app.w('minbody') + '</a></li>';
		// var f = this.bodyLeftMenu();
		// if ($(window).width() > 767)
		// ll += '<li><a class="fa ' + (f ? 'fa-circle' : 'fa-circle-o') + '" onclick="left.bodyLeftMenu(true,true)" >' + app.w('haveleftmemu') + '</a></li>';
		// ll += '<li class="hr" ><a class="fa ' + (!f ? 'fa-circle' : 'fa-circle-o') + '" onclick="left.bodyLeftMenu(true,false)" >' + app.w('noleftmenu') + '</a></li>';
		// var f = app.hideTableOption();
		// ll += '<li><a class="fa ' + (!f ? 'fa-circle' : 'fa-circle-o') + '" onclick="app.hideTableOption(false)" >' + app.w('showtableoption') + '</a></li>';
		// ll += '<li><a class="fa ' + (f ? 'fa-circle' : 'fa-circle-o') + '" onclick="app.hideTableOption(true)" >' + app.w('hidetableoption') + '</a></li>';
		// this.addRightTopIcon('bodymax', 'fa-columns', 0, '', ll);
		// 语言
		/*
		 * var ll = ''; var lang = app.getLangName(); for ( var hh in config.langlist) { ll += '<li><a class="' + hh + ' fa ' + (lang == hh ? 'fa-circle' : 'fa-circle-o') + '" onclick="app.changeLang(\'' + hh + '\')" >' + config.langlist[hh] + '</a></li>'; } this.addRightTopIcon('lang', 'fa-flag-checkered', 0, '', ll);
		 */
		// 个人中心
		var ll = '';
		ll += '<li onclick="login.isLogin(false);app.setHome();"><a>' + getIC('user') + app.getUserName() + ' &nbsp; &nbsp; ' + app.w('logout') + '</a></li>';
		var businessName = app.getBusinessName(true, false, true);
		ll += '<li onclick="app.selectBusiness(null,true);"><a>' + getIC('forumbee') + app.w('curBusiness') + ' : <span id="business">' + businessName + '</span> &nbsp; &nbsp; ' + app.w('selectBusiness') + '</a></li>';
		ll += '<li onclick="login.showMyAuthName();"><a>' + app.w('showMyAuthNameAtThisBusiness') + '</a></li>';
		ll += '<li onclick="app.changeJob();"><a>' + getIC('gg-circle') + app.w('changeJob') + '</a></li>';
		if (login.haveAuth('login', 'W'))
			ll += '<li onclick="app.showNote(' + (app.haveNote ? 1 : 0) + ',true);"><a>' + getIC(app.haveNote ? 'tags red' : 'tag') + app.w('note') + '</a></li>';
		ll += '<li onclick="login.refreshToken(0,false,true);"><a>' + app.w('refreshToken') + '</a></li>';
		ll += '<li onclick="loginWorksheet.haveNew(true,true);"><a>' + app.w('checkHaveNewWorksheet') + '</a></li>';
		ll += '<li onclick="loginWorktask.readTasktypeNew();" class="worktask"><a>' + getIC('envelope') + app.w('login.worktask.f.mail') + '</a></li>';
		ll += '<li onclick="app.readVersion(true,null,true,true);"><a>' + app.w('forceRefresh') + '</a></li>';
		if (config.debug && !app.m && (login.haveAuth('login', 'U')))
		{
			ll += '<li onclick="app.readVersion(true,null,true,false);"><a>' + app.w('changeFace') + '</a></li>';
		}
		this.addRightTopIcon('user', ' fa-user', 0, '', ll);
		this.addRightTopIcon('refresh', 'refreshpage fa-refresh');
		this.addRightTopIcon('exit', 'fa-sign-out');
	}
	/**
	 * 设置logo
	 */
	leftFun.prototype.setLogo = function()
	{
		var skin = app.getSkin();
		$('.logo img').attr('src', 'static/' + app.core + '/skin/' + skin + '/images/logo.png');
		$('.user-panel div.logo p').html(app.getWtpCaption());
		$('.minlogo img').attr('src', 'static/' + app.core + '/skin/' + skin + '/images/logo.png');
		$('.content-header .breadcrumb').css('background-image', 'url(static/' + app.core + '/skin/' + skin + '/images/logo.png)');
	}
	/**
	 * 没有需要执行的（即允许改变），返回 ture 返回是否允许改变
	 */
	leftFun.prototype.okToChangeMain = function(backfun, layerIndex)
	{
		that = this;
		if (layerIndex < 0 || layerIndex === undefined || layerIndex === null)
		{
			if (this.maincontent.returnFun)
			{
				for ( var ii in this.maincontent.returnFun)
					return that.okToChangeMain(backfun, ii);
			}
			return true;
		}
		var ii = this.getCurFullLayerIndex(layerIndex);
		if (ii > 0 && $('.fulllayer#layui-layer' + ii).length <= 0)
		{
			if (this.maincontent.returnFun && this.maincontent.returnFun[ii])
				delete this.maincontent.returnFun[ii];
			return true;
		}
		if (!login.isLogin())
		{
			if (backfun)
				backfun();
			this.maincontent.returnFun = null;
			return true;
		}
		if (backfun)
		{
			if (this.maincontent.returnFun && this.maincontent.returnFun[ii])
			{
				this.maincontent.returnFun[ii](function(isOk)
				{
					if (isOk)
					{
						delete that.maincontent.returnFun[ii];
						backfun();
					}
				});
			}
			else
				backfun();
		}
		if (this.maincontent.returnFun && this.maincontent.returnFun[ii])
			return false;
		else
			return true;
	}
	/**
	 * 设置主框的返回确认函数
	 */
	leftFun.prototype.setReturnFun = function(returnFun, layerIndex)
	{
		var ii = this.getCurFullLayerIndex(layerIndex);
		if (returnFun)
		{
			if (!this.maincontent.returnFun)
				this.maincontent.returnFun = {};
			this.maincontent.returnFun[ii] = returnFun;
		}
		else if (layerIndex === true)
			this.maincontent.returnFun = null;
		else if (this.maincontent.returnFun && this.maincontent.returnFun[ii])
			delete this.maincontent.returnFun[ii];
	}
	/**
	 * 取得当前全屏layerId
	 */
	leftFun.prototype.getCurFullLayerIndex = function(layerIndex)
	{
		return layerIndex || this.maincontent.layerIndex || 0;
	}
	leftFun.prototype.setMainContentHtml = function(html, onActiveFun, noIcons, mainIcons, returnFun, justHtml, toHome, closeFun, delayms)
	{
		toHome = !!toHome;
		var inMain = toHome || !app.vm;
		if (inMain && this.maincontent.closeFun)
		{
			// 上一个关闭函数
			this.maincontent.closeFun();
			this.maincontent.closeFun = null;
		}
		if (this.setMainContentHtml.home && toHome && app.vm)
			return;
		if (this.setMainContentHtml.home != toHome)
		{
			$('.content-wrapper').addClass('home');
			if (toHome)
				closeFullLayer();
			this.setMainContentHtml.home = !!toHome;
		}
		var that = this;
		if (html)
		{
			if (!justHtml)
			{
				var st = inMain ? ('style="min-height:' + app.getMainHeight() + 'px;"') : '';
				var html = '<div ' + st + ' class="box tablebox nav-tabs-custom desk' + (noIcons ? '' : ' icons') + (!mainIcons ? '' : ' mainicons') + '"><div class="box-body dataTables_wrapper">' + html + '</div></div>';
				if (toHome && app.vm)
					html = this.getHomeHtml(html);
				if (!app.vm && this.navBarList && this.navBarList.length > 0)
					html = '<span class="fa fa-close righttopclose test"></span>' + html;
			}
			if (inMain)
			{
				that.maincontent.layerIndex = 0;
				$('#maincontent').html(html);
			}
			else
			{
				that.maincontent.layerIndex = showFullLayer('', html, function()
				{
					if (closeFun)
						closeFun();
					var n = getFullLayerNumber();
					if (that.navBarList && that.navBarList.length > n)
						that.navBarList.length = n;
					t = that.getRunHeadNav();
					app.hash(t.path);
				}, false, false, '', false, onActiveFun, null, false, null, delayms);
				setTimeout(function()
				{
					$('#layui-layer' + that.maincontent.layerIndex + ' .layui-layer-title>span').html(that.getRunHeadNav().cap);
				}, 10);
				return;
			}
		}
		else
		{
			$('#maincontent').html('');
		}
		this.maincontent.onActiveFun = onActiveFun || null;
		this.maincontent.returnFun = returnFun || null;
		if (inMain)
			this.maincontent.closeFun = closeFun || null;
	}
	leftFun.prototype.getRunHeadNav = function()
	{
		var cap = '';
		var path = '';
		for (var i = 0; i < this.navBarList.length; i++)
		{
			var t = this.navBarList[i];
			cap += (cap ? ' . ' : '') + t['cap'].trim();
			path = t.id;
		}
		return {
			cap : cap,
			path : path
		};
	}
	leftFun.prototype.getHomeHtml = function(html)
	{
		var h = '';
		h += '<div class="facetop">';
		h += '<span class="facecap p1">智力库</span><span class="facecap p2">3.0</span>';
		h += html;
		h += '</div>';
		return h;
	}
	leftFun.prototype.runHeadNav = function(path, datalevel, byhand)
	{
		var that = this;
		if (!this.okToChangeMain())
		{
			this.okToChangeMain(function()
			{
				that.runHeadNav(path, datalevel, byhand);
			});
			return;
		}
		closeFullLayer();
		if (app.vm && path == 'home')
		{
			app.selectBusiness(null, true);
			return;
		}
		if (datalevel >= 1 && !isNaN(datalevel))
		{
			if (this.navBarList.length > datalevel - 1)
				this.navBarList.length = datalevel - 1;
		}
		var pn = parseInt(path);
		if (pn == path && !isNaN(pn))
		{
			if (this.navBarList && this.navBarList.length > pn)
			{
				var fun = this.navBarList[pn].fun;
				if (fun)
					fun();
				this.navBarList.length = pn + 1;
				this.showNavBar();
			}
		}
		else
		{
			if (path == 'home' || !path)
				this.goPage('', false, false, byhand);
			else
			{
				if ((path + ' ').indexOf('.') >= 0)
					return false;
				var sv = $('#roottree #' + path);
				if (!sv.length)
					return false;
				if (sv.hasClass('show-tab'))
					this.goPage(path);
				else
				{
					this.showTree(path);
					this.showTreeToMain(path);
				}
			}
		}
	}
	leftFun.prototype.bodyLeftMenu = function(action, isSetM, tempM)
	{
		if (tempM === true || tempM === false)
			var m = tempM;
		else
		{
			var m = (app.getStorage('bodyLeftMenu') == 'yes' && !app.vm);
			if (arguments.length >= 2)
			{
				if (isSetM === true || isSetM === false || isSetM === null)
				{
					if (isSetM === null)
						m = !m;
					else
						m = isSetM;
					if (m && $(window).width() <= 767)
						return;
					app.setStorage('bodyLeftMenu', m ? 'yes' : 'no');
					this.rightTopMenu();
				}
			}
		}
		m = m && $(window).width() > 767;
		if (action)
		{
			resizeFullLayer(m);
			if (m)
			{
				$('body').removeClass('sidebar-collapse');
				$('.main-sidebar').removeClass('hidden');
			}
			else
			{
				$('body').addClass('sidebar-collapse');
				$('.main-sidebar').addClass('hidden');
			}
			setTimeout(function()
			{
				app.setAppSize();
			}, 333);
		}
		return m;
	}
	// /////////////////////////////////////////////////////////////////////////////////////
	// 添加右上角的图标
	leftFun.prototype.addRightTopIcon = function(name, icon, number, numberclass, dropdownli)
	{
		var li = '<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">';
		li += '<i class="fa white ' + icon + '"></i>';
		if (number)
		{
			li += '<span class="label ' + numberclass + '">' + number + '</span>';
		}
		li += '</a>';
		if (dropdownli)
		{
			li += '<ul class="dropdown-menu">';
			li += dropdownli;
			li += '</ul>';
		}
		if ($('#RightTopIconUL #' + name).length > 0)
			$('#RightTopIconUL #' + name).html(li);
		else
		{
			li = '<li class="dropdown messages-menu" id="' + name + '">' + li + '</li>';
			$('#RightTopIconUL').append(li);
		}
	}
	window.left = new leftFun();
}());
